package LeetCode.NumOffer;

/**
 * 整数的n次方
 * @author lumin
 * @date 2022/04/30 19:57
 **/
public class Num16 {
    public static double myPow(double x, int n) {
        double temp = x;
        if(n == 0.0 || x == 1.0){
            return 1.0;
        }else if(x == 0.0){
            return 0.0;
        }else if(n > 0){
            for (int i = 1; i < n; i++) {
                x *= temp;
            }
        }else{
            n = -n;
            for (int i = 1; i < n; i++) {
                x *= temp;
            }
            x = 1 / x;
        }
        return x;
    }

    public static void main(String[] args) {
        System.out.println(myPow(2, 2));
    }
}